/*
 * mox_comm_chans.h
 *
 *  Created on: Jul 11, 2010
 *      Author: jmonk
 */

#ifndef MOX_COMM_CHANS_H_
#define MOX_COMM_CHANS_H_

#include <xs1.h>
#include <xccompat.h>

#ifdef __XC__
static inline unsigned mox_chan_in_wd(streaming chanend c)
#else
static inline unsigned mox_chan_in_wd(chanend c)
#endif
{
  register unsigned value;
  asm("in %0, res[%1]":"=r"(value):"r"(c));
  return value;
}

#ifdef __XC__
static inline void mox_chan_out_wd(streaming chanend c, unsigned value)
#else
static inline void mox_chan_out_wd(chanend c, unsigned value)
#endif
{
  __asm__ (
    "out res[%0], %1" :
    /* no outputs */ :
    "r"(c), "r"(value)
  );
}

#ifdef __XC__
static inline unsigned char mox_chan_in(streaming chanend c)
#else
static inline unsigned char mox_chan_in(chanend c)
#endif
{
  unsigned value;
  asm("int %0, res[%1]":"=r"(value):"r"(c));
  return value;
}

#ifdef __XC__
static inline void mox_chan_out(streaming chanend c, unsigned char value)
#else
static inline void mox_chan_out(chanend c, unsigned char value)
#endif
{
  __asm__ (
    "outt res[%0], %1" :
    /* no outputs */ :
    "r"(c), "r"(value)
  );
}

#endif /* MOX_COMM_CHANS_H_ */
